﻿using System;

namespace uTILLIty.ADExtractor.Core.Formatters
{
	public class GuidFormatter : IFormatter
	{
		public string Format(string attributeName, object value, string valueSeparator)
		{
			var bytes = value as byte[];
			return bytes == null
				? (value ?? "").ToString()
				: new Guid(bytes).ToString();
		}

		public bool CanFormat(string attributeName)
		{
			return IsGuidProperty(attributeName);
		}

		protected virtual bool IsGuidProperty(string prop)
		{
			return prop.StartsWith("Guid", StringComparison.InvariantCultureIgnoreCase) ||
						 prop.EndsWith("Guid", StringComparison.InvariantCultureIgnoreCase);
		}
	}
}